package com.demo.member;

import com.demo.AppletConstant;
import com.demo.util.Utils;

import java.util.HashMap;
import java.util.Map;

public class ActiveMemberCard {

    public static void main(String[] args) throws Exception {

        String resultStr = activeMemberCard();

        System.out.println("-------获取activeMemberCard信息:"+resultStr+"---------");

    }

    public static String activeMemberCard() throws Exception {

        //调用地址
        String url = "https://open.95516.com/open/access/1.0/activeMemberCard";
        //拼装参数Map
        Map<String, String> params = new HashMap<String, String>(0);

        params.put("appId", AppletConstant.APP_ID);

        params.put("cardTemplateId", "");

        params.put("openId", AppletConstant.openId);

        params.put("upMemberCardNo", "");

        params.put("merchantMemberCardNo", "");

        params.put("initBonus", "");

        params.put("initBalance", "");

        params.put("initLevel", "");

        params.put("source", "");

        params.put("IsNewMembership", "");

        //生成随即字符串
        String nonceStr = Utils.createNonceStr();
        params.put("nonceStr", nonceStr);

        //生成时间戳
        String timestamp = String.valueOf(System.currentTimeMillis()/1000);
        params.put("timestamp", timestamp);

        String signature = Utils.sign(params,AppletConstant.SIGN_KEY_PACKET);//进行加密签名
        params.put("signature", signature);

        System.out.println("生成入参和签名："+params);

        //针对敏感字段加密
        Utils.encryptedParamMap(AppletConstant.SYMMETRIC_KEY, params, "upMemberCardNo","merchantMemberCardNo", "initBonus", "initBalance");

        //发送请求
        String resultStr = Utils.sendPostGson(url, params);
        return resultStr;

    }

}
